<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>基金列表</title>

<script src="${ctx}/FundTrans/assets/jq/jquery-1.4.4.min.js"></script>
<script>

</script>

</head>
<h3>基金产品列表</h3>
<body>
	<div style="width: 990; height: 530;">
		<div id="fundlist" style="margin-left: 180px;"></div>
	</div>
	<br />
	<br />
	<!-- 分页设计部分 -->
	<div style="width: 990; text-align: center">
		<div style="background-color: silver;">
			<input id="prev" type="button" value="上一页" /> <span id="currentpage">1</span>
			<input id="next" type="button" value="下一页" /> <input id="jumppage"
				type="text" size="2" /> <input id="jumpbut" type="button"
				value="跳转" /> 总记录：<span id="totalNum">0</span> 总页数：<span
				id="totalpage">0</span>
		</div>
	</div>
</body>
<script>
//删除事件
function deleteFund(a,event) { 

	 var fundname=$(a).attr("title");
	 $.ajax({
		type : "POST", //设置ajax方法提交数据的形式   
		url : "deletefund", //把数据提交到ok.php   
		data : {
			"fundName" : fundname
		},
		success : function(msg) { 
			alert("删除成功!");
			getFundList($("#currentpage").html(), 10);
		}
	});

}

$(function() {

	getFundList(1, 10);

	//分页点击事件
	$("#prev").click(function() {
		var currentpages = $("#currentpage").html();
		if (currentpages <= 1) {
			alert("已经到头啦!");
			return;
		}
		getFundList(currentpages - 1, 10);
	});
	$("#next").click(function() {
		var currentpages = $("#currentpage").html();
		var totalpages = $("#totalpage").html();
		if (currentpages >= totalpages) {
			alert("已经到尾啦!");
			return;
		}
		getFundList(parseInt(currentpages) + 1, 10);
	});
	$("#jumpbut").click(function() {
		var jumppages = $("#jumppage").val();
		var totalpages = $("#totalpage").html();
		if (jumppages<1||jumppages>totalpages) {
			alert("输入有误!");
			return;
		}
		getFundList(jumppages, 10);
	});
});
function getFundList(page, num) {
	$.ajax({ //调用jquery的ajax方法   
		type : "POST", //设置ajax方法提交数据的形式   
		url : "getfund", //把数据提交到ok.php   
		data : {
			"pages" : page,
			"num" : num
		},
		success : function(msg) { //提交成功后的回调，ms是json格式

			$("#fundlist").empty();

			//设置总页数，记录数
			$("#totalNum").html(msg.maxRowCount);
			$("#totalpage").html(msg.maxPage);
			$("#currentpage").html(msg.curPage);
			var table = $("<table border='1' cellspacing='0' cellpadding='10'>");
			table.appendTo($("#fundlist"));

			var tr = $("<tr><th>ID</th><th>名称</th><th>价格</th><th>简介</th><th>状态</th><th>生成时间</th><th>操作</th></tr>");
			tr.appendTo(table);
			var info = msg.data;
			for (var i = 0; i < info.length; i++) {
				var td = $("<tr><td>"
						+ info[i].id
						+ "</td>"
						+ "<td>"
						+ info[i].name
						+ "</td>"
						+ "<td>"
						+ info[i].price
						+ "</td>"
						+ "<td>"
						+ info[i].description
						+ "</td>"
						+ "<td>"
						+ info[i].status
						+ "</td>"
						+ "<td>"
						+ info[i].createTime
						+ "</td>"
						+ "<td>"
						+ "<a id='updatefund' href='./fund_update.jsp?name="
						+info[i].name+"&price="+info[i].price+"&descri="
						+info[i].description+"&status="+info[i].status
						+"' title="
						+info[i].name
						+">更新</a>&nbsp"
						+ "<a id='deletefund' href='javascript:void(0);' onclick='deleteFund(this,event)' title="
						+info[i].name+">删除</a>"
						+ "</td></tr>");
				td.appendTo(table);
			}
			$("#fundlist").append("</table>");
		}
	});
}
</script>
</html>